define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'sjchange/index' + location.search,
                    add_url: 'sjchange/add',
                    edit_url: 'sjchange/edit',
                    del_url: 'sjchange/del',
                    multi_url: 'sjchange/multi',
                    import_url: 'sjchange/import',
                    upload_url: 'sjchange/shengh',
                    table: 'sjchange',
                }
            });

            var table = $("#table");

            // 初始化表格
            var ids = Table.api.selectedids(table);
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'fname', title: __('Fname'), operate: 'LIKE'},
                        {field: 'fpath_files', title: __('Fpath_files'), operate: false, formatter: Table.api.formatter.files},
                        {field: 'fbecause', title: __('Fbecause'), operate: 'LIKE'},
                        // {field: 'status', title: __('Status'), searchList: {"未签收":__('未签收'),"已签收":__('已签收')}, formatter: Table.api.formatter.status},
                        {field: 'status', title: __('Status'), searchList: {"未签收":__('未签收'),"已签收":__('已签收')}, formatter: function(r,v){
                               console.log(v+"ppppppppppp");
                               if(v.status55!=null){
                                    return v.status55.status==0 ? '<span style="color:red">未审核</span>':'<span style="color:green">已审核</span>';     
                               }else{
                                return '<span style="color:red">未审核</span>';  
                            }
                                                          
                        }},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'admin.nickname', title: __('Admin.nickname'), operate: 'LIKE',formatter:function(r,v){
                            // console.log(r,v);
                            return v.admin_ids;
                        }
                    },
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, 
                        buttons: [{
                            name: '审核',
                            title:__('审核'),
                            text: '审核',
                            icon: 'fa fa-cloud-download',
                            classname: 'btn btn-xs btn-info',
                            url: 'sjchange/shengh?ids='+ids,
                            visible:function(row){
                                if(row.status55!=null){
                                    if(row.status55.status==1){
                                        return false;
                                    }
                                }
                               
                                return true;
                            }
                          }],
                        
                        formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        shengh: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
